package org.apache.rocketmq.remoting.rpc;

import com.google.common.base.MoreObjects;
import org.apache.rocketmq.remoting.CommandCustomHeader;

import java.util.Objects;

/**
 * @课程描述:从零带你写框架系列中的课程，整个系列包含netty，xxl-job，rocketmq，nacos，sofajraft，spring，springboot，disruptor，编译器，虚拟机等等。
 * @author：陈清风扬，个人微信号：chenqingfengyangjj。
 * @date:2024/12/27
 * @方法描述：RPC请求的请求头
 */
public abstract class RpcRequestHeader implements CommandCustomHeader {

    protected String ns;

    protected Boolean nsd;

    protected String bname;

    protected Boolean oway;


    @Deprecated
    public String getBname() {
        return bname;
    }


    @Deprecated
    public void setBname(String brokerName) {
        this.bname = brokerName;
    }

    public String getBrokerName() {
        return bname;
    }

    public void setBrokerName(String brokerName) {
        this.bname = brokerName;
    }

    public String getNamespace() {
        return ns;
    }

    public void setNamespace(String namespace) {
        this.ns = namespace;
    }

    public Boolean getNamespaced() {
        return nsd;
    }

    public void setNamespaced(Boolean namespaced) {
        this.nsd = namespaced;
    }

    public Boolean getOneway() {
        return oway;
    }

    public void setOneway(Boolean oneway) {
        this.oway = oneway;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RpcRequestHeader header = (RpcRequestHeader) o;
        return Objects.equals(ns, header.ns) && Objects.equals(nsd, header.nsd) && Objects.equals(bname, header.bname) && Objects.equals(oway, header.oway);
    }


    @Override
    public int hashCode() {
        return Objects.hash(ns, nsd, bname, oway);
    }


    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("namespace", ns)
                .add("namespaced", nsd)
                .add("brokerName", bname)
                .add("oneway", oway)
                .toString();
    }
}
